package com.jd.basic.dto;

import com.jd.basic.util.MD5Utils;
import com.jd.basic.util.StrUtils;
import com.jd.user.domain.User;
import lombok.Data;
import org.springframework.context.annotation.Primary;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
public class BinderDto {
    @NotBlank
    private String phone;
    @NotBlank
    private String phoneCode;
    @NotBlank
    private String token;
    @NotBlank
    private String openId;
    @NotBlank
    private String type;

    public User getUser(){
        //盐值
        String salt = StrUtils.getComplexRandomString(32);
        // 盐值 + 密码
        String pw = MD5Utils.encrypByMd5(salt + "1");
        return User
                .builder()
                .createtime(new Date())
                .salt(salt)
                .password(pw)
                .state(1)
                .phone(this.phone)
                .username(this.phone)
                .build();
    }
}
